<template>
  <div class="header">
    <div class="container clearfix">
      <ul class="clearfix">
        <li
          v-for="(item, index) in data"
          :key="index"
          @click="handleTeam({ [index]: item })"
        >
          {{ index }}
          <div class="hidden" v-if="data[index]">
            <div
              class="item"
              v-for="(i, current) in data[index]"
              :key="i"
              @click.stop="handleClickItem({ [index]: data[index] }, current)"
            >
              {{ i }}
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import headerData from "../../data/headerData";
export default {
  name: "Header",
  data() {
    return {
      data: headerData,
    };
  },
  methods: {
    FUHEMTHODS(item, current) {
      this.$store.commit("SETDATA", item);
      this.$store.commit("SETINDEX", current);
      this.$router.push({
        name: "Jdtxgz",
      });
    },
    handleClickItem(item, current) {
      this.FUHEMTHODS(item, current);
    },
    handleTeam(item) {
      const keys = Object.keys(item);
      if (keys[0] === "首页") {
        return this.$router.push({
          path: "/",
        });
      }
      this.FUHEMTHODS(item, 0);
    },
    windowScroll(e) {
      const scrollY = this.getScrollTop();
      if (scrollY > 190) {
        document.querySelector(".header").className = "header fix";
      }
    },
    getScrollTop() {
      let scrollTop = 0;
      if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
      } else if (document.body) {
        scrollTop = document.body.scrollTop;
      }
      return scrollTop;
    },
  },
  mounted() {},
};
</script>

<style lang="less">
.fix {
  position: fixed;
  width: 100%;
  top: 0;
}
.header {
  background: #393e46;
  min-width: 100%;
  .clearfix:after {
    visibility: hidden;
    display: block;
    font-size: 0;
    content: " ";
    clear: both;
    height: 0;
  }
  .container {
    width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    ul {
      flex-wrap: nowrap;
    }
    li:hover .hidden {
      opacity: 1;
      visibility: visible;
    }
    li {
      float: left;
      line-height: 60px;
      color: white;
      padding: 0 20px;
      min-height: 60px;
      position: relative;
      font-size: 16px;
      cursor: pointer;
      .hidden {
        white-space: nowrap;
        transition: all 0.7s ease;
        position: absolute;
        left: -5px;
        z-index: 19;
        background: #48555c;
        box-shadow: 2px 2px 8px hsl(0deg 0% 66% / 50%);
        padding: 0 0 0px 0;
        color: #fff;
        opacity: 0;
        visibility: hidden;

        .item {
          padding: 0px 20px;
          height: 50px;
          text-align: center;
          line-height: 50px;
        }
        .item:hover {
          background: #4481f6;
          color: #fff;
        }
      }
    }
  }
}
</style>